﻿Imports System.Data.SqlClient
Public Class dbCustomer
    Dim Var As New varDeclare

    Public Function GetCustomerList() As DataSet
        Dim connection As SqlConnection
        Dim adapter As SqlDataAdapter
        Dim command As New SqlCommand
        Dim ds As New DataSet
        connection = New SqlConnection(Var.SUISConn)

        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = "SELECT * FROM vCustomer"
        adapter = New SqlDataAdapter(command)
        adapter.Fill(ds)
        connection.Close()
        Return ds
    End Function

    Public Function GetCustAccountList() As DataSet
        Dim connection As SqlConnection
        Dim adapter As SqlDataAdapter
        Dim command As New SqlCommand
        Dim ds As New DataSet
        connection = New SqlConnection(Var.SUISConn)

        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = "SELECT * FROM v_CustAccountList"
        adapter = New SqlDataAdapter(command)
        adapter.Fill(ds)
        connection.Close()
        Return ds
    End Function

    Public Function CustomerManagement(Code As String, Company As String, NPWP As String, Terms As String, ARAccount As String, _
                                  APAccount As String, Type As String) As String
        Dim connection As SqlConnection
        Dim command As New SqlCommand
        connection = New SqlConnection(Var.SUISConn)

        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.StoredProcedure
        command.CommandText = "proc_CustomerManagement"
        command.Parameters.Add("@Code", SqlDbType.VarChar).Value = Code
        command.Parameters.Add("@Company", SqlDbType.VarChar).Value = Company
        command.Parameters.Add("@NPWP", SqlDbType.VarChar).Value = NPWP
        command.Parameters.Add("@Terms", SqlDbType.VarChar).Value = Terms
        command.Parameters.Add("@ARAccount", SqlDbType.VarChar).Value = ARAccount
        command.Parameters.Add("@APAccount", SqlDbType.VarChar).Value = APAccount
        command.Parameters.Add("@Type", SqlDbType.VarChar).Value = Type
        Dim result As Object = command.ExecuteScalar()
        connection.Close()
        Return Convert.ToString(result)
    End Function
End Class
